

// 位置框
let locationBox = document.getElementsByClassName('location')[0];
let locationText = document.getElementsByClassName('location_text')[0];
// 首页
let homeBox = document.getElementsByClassName('home_box')[0];
// 协会简介
let associationProfile = document.getElementsByClassName('association_profile')[0];
// 协会公告
let bulletinBox = document.getElementsByClassName('bulletin_box')[0];
// 公告列表
let bulletinListBox = document.getElementsByClassName('bulletin_list_box')[0];
// 协会公告详情页面
let bulletinDetails = document.getElementsByClassName('bulletin_deatils_box')[0];
// 活动页
let activityBox = document.getElementsByClassName('activity_box')[0];
// 活动列表页面
let activityList = document.getElementsByClassName('activity_list')[0];
// 活动详情页面
let activityDetails = document.getElementsByClassName('activity_details')[0];
// 理事单位
let governingUnits = document.getElementsByClassName('governing_units')[0];
// 会员风采
let vipf = document.getElementsByClassName('vipf')[0];
// 在线投稿
let newsBox = document.getElementsByClassName('sub')[0];
// 二级下属机构
let levelTwo = document.getElementsByClassName('level_two')[0];
// 404页面
let undefinedBox = document.getElementsByClassName('undefined_box')[0];

let thisLocation = [{
    "path": "/",
    title: "首页"
}];


//  当前位置点击处理
function locationChange(loPath) {
    if(loPath){
        navCheck(loPath);
    }
}

//  位置列表渲染
function locationListRender() {
    let loList = "";
    thisLocation.forEach(element => {
        loList += `<li onclick="locationChange('${element.path}')">${element.title}</li>`;
    });

    locationText.innerHTML = loList;
}

// 位置列表切换处理
function locationActivity(type,locationObj) {
    console.log(type,locationObj);
    if (type === 'add') {
    } else if (type ==='check') {
        thisLocation = [];
       
    }
    thisLocation.push(locationObj);
    locationListRender();
}

//  活动页列表点击事件处理
function activityCheck(check){
    locationActivity("add", {
        path: "",
        title: "某某活动详情"
    })
    checkToActiveDetail();
    
}
//  公告页列表点击事件处理
function bulletinCheck(check){
   
    locationActivity("add", {
        path: "",
        title: "某某公告详情"
    })
        checkToBulletinDetail();
    
}


// 活动页切换列表
function checkToActiveList(){
    if (activityList.style.display === 'none') {
        activityList.style.display = 'block';
        activityDetails.style.display = 'none';
    }
}
// 活动页切换详情
function checkToActiveDetail(){
    if (activityDetails.style.display === 'none') {
        activityList.style.display = 'none';
        activityDetails.style.display = 'block';
    }
}
// 公告页切换列表
function checkToBulletinList(){
    if (bulletinListBox.style.display === 'none') {
        bulletinListBox.style.display = 'block';
        bulletinDetails.style.display = 'none';
    }
}
// 公告页切换详情
function checkToBulletinDetail(){
    if (bulletinDetails.style.display === 'none') {
        bulletinListBox.style.display = 'none';
        bulletinDetails.style.display = 'block';
    }
}


// 头部菜单点击会回调
router((path, route) => {
    console.log(locationBox.style.display);
    if (path === '/0') {
        locationBox.style.display = 'none';
    } else {
        if (locationBox.style.display === 'none') {
            locationBox.style.display = 'block';
        }
    }

    if (homeBox.style.display === 'block') {
        homeBox.style.display = 'none';
    }
    if (associationProfile.style.display === 'block') {
        associationProfile.style.display = 'none';
    }
    if (bulletinBox.style.display === 'block') {
        bulletinBox.style.display = 'none';
    }
    if (activityBox.style.display === 'block') {
        activityBox.style.display = 'none';
    }
    if (governingUnits.style.display === 'block') {
        governingUnits.style.display = 'none';
    }
    if (vipf.style.display === 'block') {
        vipf.style.display = 'none';
    }
    if (newsBox.style.display === 'block') {
        newsBox.style.display = 'none';
    }
    if (levelTwo.style.display === 'block') {
        levelTwo.style.display = 'none';
    }
    if (undefinedBox.style.display === 'block') {
        undefinedBox.style.display = 'none';
    }


    //  切换页面
    switch (path) {
        case '/0':
        case '/':
            homeBox.style.display = 'block';
            break;
        case '/1':
            associationProfile.style.display = 'block';
            break;
        case '/2':
            bulletinBox.style.display = 'block';
            checkToBulletinList();
            break;
        case '/3':
            activityBox.style.display = 'block';
            checkToActiveList();
            break;
        case '/4':
            governingUnits.style.display = 'block';
            break;
        case '/5':
            vipf.style.display = 'block';
            break;
        case '/6':
            newsBox.style.display = 'block';
            break;
        case '/7':
            levelTwo.style.display = 'block';
            break;
        default:
            undefinedBox.style.display = 'block';
            break;
    }
})

window.onload = () => {
    navCheck("/0");
}